package com.doubao.doubao.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.doubao.doubao.common.api.ApiResult;
import com.doubao.doubao.mapper.BmsGroupTrueMapper;
import com.doubao.doubao.model.entity.BmsGroupTrue;
import com.doubao.doubao.model.vo.GroupVO;
import com.doubao.doubao.service.IBmsGroupTrueervice;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/groupList")
public class BmsGroupTrueController extends BaseController {

    @Resource
    private IBmsGroupTrueervice iBmsGroupTrueervice;
    @Resource
    BmsGroupTrueMapper bmsGroupTrueMapper;


    @PostMapping("/JoinGroup")
    public ApiResult<BmsGroupTrue> JoinGroup(@RequestBody BmsGroupTrue bmsGroupTrue) {
        BmsGroupTrue res =  bmsGroupTrueMapper.selectOne(Wrappers.<BmsGroupTrue>lambdaQuery()
                .eq(BmsGroupTrue::getGroupId,bmsGroupTrue.getGroupId())
                .eq(BmsGroupTrue::getUserId,bmsGroupTrue.getUserId())
        );
        if(res!=null){
            return ApiResult.failed("你已经在这个群里了，请不要重复添加");
        }
        iBmsGroupTrueervice.save(bmsGroupTrue);
        return ApiResult.success(bmsGroupTrue);
    }

//    @PostMapping("/JoinGroup")
//    public ApiResult<BmsGroupTrue> save(@RequestBody BmsGroupTrue bmsGroupTrue){
//        bmsGroupTrueMapper.insert(bmsGroupTrue);
//        return ApiResult.success(bmsGroupTrue);
//    }

    @GetMapping("/GroupSearch")
    public ApiResult<List<GroupVO>> getGroupID(@RequestParam(value = "groupid", defaultValue = "1") String groupid) {
        List<GroupVO> lstGroup = iBmsGroupTrueervice.getGroupId(groupid);
        return ApiResult.success(lstGroup);
    }





}
